//n皇后问题解决

#include <iostream>
#include <vector>
using namespace std;
template<class U>
void printvec(vector<vector<U>> vec);
void printvec(vector<string> vec);
void put_queen(int x, int y, vector<vector<int>>& att,int n);
void return_queen(int x, int y, vector<vector<int>>& att,int n);


//回溯算法的实现
static unsigned long cnt = 0;
void backtracking(vector<vector<string>>& result,vector<string>& board, vector<vector<int>>& attack, int ystartIndex,int n) {

    if (ystartIndex == n) { result.push_back(board); cnt++; return; }

    //for循环是遍历行，递归遍历列
    for (int i = 0; i < n; i++) {
        if (attack[ystartIndex][i] == 0) {

            board[ystartIndex][i] = 'Q';
            put_queen(i, ystartIndex, attack,n);
            backtracking(result,board, attack, ystartIndex + 1,n);
            return_queen(i, ystartIndex, attack,n);
            board[ystartIndex][i] = '.';

        }
    }
}







template<class U>
void printvec(vector<vector<U>> vec) {
    for (int i = 0; i < vec.size(); i++) {
        for (int j = 0; j < vec.size(); j++)
            cout << vec[i][j] << " ";
        cout << endl;
    }
    cout << endl;
}

void printvec(vector<string> vec){
    for (int i = 0; i < vec.size(); i++) {
        for (int j = 0; j < vec.size(); j++)
            cout << vec[i][j] << " ";
        cout << endl;
    }
    cout << endl;
}


//放置queen将其八个方向设为不可放置
void put_queen(int x, int y, vector<vector<int>>& att,int n) {
    //左右下上左下，左上，右下右上
    static const int dx[] = { -1,1,0,0,-1,-1,1,1 };
    static const int dy[] = { 0,0,-1,1,-1,1,-1,1 };

    att[y][x]++;        //注意，这里用的是++,return 用的是--，而不是单纯的设置1 0，因为一个地方可能有两个皇后攻击
    for (int i = 0; i < 8; i++) {
        for (int j = 1; x + dx[i] * j < n && x + dx[i] * j >= 0 && y + dy[i] * j >= 0 && y + dy[i] * j < n; j++) {
            att[y + dy[i] * j][x + dx[i] * j]++;
        }
    }
}
//恢复之前的状态
void return_queen(int x, int y, vector<vector<int>>& att,int n) {
    //左右下上左下，左上，右下右上
    static const int dx[] = { -1,1,0,0,-1,-1,1,1 };
    static const int dy[] = { 0,0,-1,1,-1,1,-1,1 };

    att[y][x]--;
    for (int i = 0; i < 8; i++) {
        for (int j = 1; x + dx[i] * j < n && x + dx[i] * j >= 0 && y + dy[i] * j >= 0 && y + dy[i] * j < n; j++) {
            att[y + dy[i] * j][x + dx[i] * j]--;
        }
    }
}




int main()
{
    int n;
    cin >> n;
    vector<vector<string>> result;
    vector<vector<int>> attack(n, vector<int>(n,0));
    vector<string> board(n, string(n,'.'));
    backtracking(result,board, attack, 0, n);
    cout << cnt;

    return 0;
}

